from django.http import HttpResponse

from django.utils.deprecation import MiddlewareMixin


class UserAgentMiddleware(MiddlewareMixin):

    def process_request(self, request):
        print("UserAgentMiddleware", '请求 处理')
        request.user_agent = request.META.get('HTTP_USER_AGENT')
        print(request.user_agent)
    def process_response(self, request, response):
        print("UserAgentMiddleware",'响应 处理')
        if request.META.get('HTTP_USER_AGENT') in ["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36"]:
            pass
        else:
            return HttpResponse('请使用谷歌浏览器访问')

        return response